package com.bw.module_home.viewmodel

import androidx.lifecycle.viewModelScope
import com.bw.module_home.model.HomeResult
import com.baway.home.repo.HomeRepo
import com.bw.lib_common.vm.BaseViewModel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class HomeViewModel : BaseViewModel<List<HomeResult>>() {
    private val homeRepo = HomeRepo()

    fun getHomeList(page: Int, size: Int){
        viewModelScope.launch {
            val result = homeRepo.getHomeList(page, size)
            if (result.code == 200){
                mSuccessLiveData.value = result.data.filter {
                    !it.content.isNullOrEmpty()
                    && !it.title.isNullOrEmpty()
                    && !it.type.isNullOrEmpty()
                }
            }else{
                mErrorLiveData.value = result.message
            }
        }
    }
}

